<template>
  <div class="layout">
    <div class="search">
      <div class="location" @click="getLocation">
        {{ city }}
        <van-icon class="icon" name="arrow-down">
          <span class="gun">|</span>
        </van-icon>
      </div>
      <van-search placeholder="请输入搜索关键词" />
      <van-icon name="guide-o" class="map" color="#fff" />
    </div>

    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="item in images" :key="item.id">
        <img v-lazy="'http://liufusong.top:8080' + item.imgSrc" />
      </van-swipe-item>
    </van-swipe>
    <van-grid :border="false">
      <van-grid-item @click="toggle('/lookup', 1)"
        ><img src="../assets/1.png" alt="" />
        <h2>整租</h2></van-grid-item
      >
      <van-grid-item @click="toggle('/lookup', 1)"
        ><img src="../assets/0.png" alt="" />
        <h2>合租</h2></van-grid-item
      >
      <van-grid-item @click="toggle('/lookup')"
        ><img src="../assets/2.png" alt="" />
        <h2>地图找房</h2></van-grid-item
      >
      <van-grid-item @click="toggle('/lease')"
        ><img src="../assets/3.png" alt="" />
        <h2>去出租</h2></van-grid-item
      >
    </van-grid>
    <div class="content">
      <div class="group">
        <div
          class="am-flexbox-item"
          v-for="item in amflexboxitem"
          :key="item.id"
        >
          <img :src="'http://liufusong.top:8080' + item.imgSrc" alt="" />
          <div class="cont">
            <div class="title">{{ item.title }}</div>
            <div class="desc">{{ item.desc }}</div>
          </div>
        </div>
        <!-- <div class="am-flexbox-item"></div>
      <div class="am-flexbox-item"></div>
      <div class="am-flexbox-item"></div> -->
      </div>
    </div>
    <div class="titleandmore">
      <div class="left">租房小组</div>
      <div class="right">更多</div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "index-page",
  components: {},
  props: {},
  data() {
    return {
      images: [],
      amflexboxitem: [],
      city: localStorage.getItem("city")
        ? localStorage.getItem("city")
        : "上海",
    };
  },
  computed: {},
  watch: {},
  async created() {
    const { body } = await request({ url: "/home/swiper" });

    this.images = body;
    const { body: data } = await request({ url: "/home/groups" });
    this.amflexboxitem = data;
  },
  methods: {
    getLocation() {
      this.$router.push("/location");
    },
    toggle(value, num) {
      this.$router.push(value);
      this.$emit("act", num);
    },
  },
};
</script>

<style scoped lang="less">
.van-swipe {
  width: 100%;

  img {
    height: 212px;
  }
  ::v-deep .van-swipe__indicator {
    width: 8px;
    height: 8px;
    background-color: #ccc;
  }
  ::v-deep van-swipe__indicator--active {
    background-color: #888;
  }
}
.layout {
  position: relative;
  .search {
    .location {
      border-radius: 3px 0 0 3px;
      position: absolute;
      height: 34px;
      width: 64px;
      background-color: #f7f8fa;
      color: #333;
      z-index: 222;
      transform: translate(-50%, -50%);
      left: 15%;
      top: 9%;
      line-height: 34px;
      text-align: left;
      font-size: 14px;
      padding: 0 6px;
      .icon {
        font-size: 12px;
      }
    }
    .van-search {
      border-radius: 0 3px 3px 0;
      position: absolute;
      z-index: 222;
      padding: 0;
      transform: translate(-50%, -50%);
      left: 55%;
      top: 9%;
      width: 230px;
    }
  }
  .map {
    position: absolute;
    z-index: 222;
    transform: translate(-50%, -50%);
    left: 90%;
    top: 8%;
    width: 20px;
    height: 20px;
    font-size: 30px;
  }
  .gun {
    font-size: 20px;
    margin-left: 10px;
    color: #eee;
  }
}
.van-grid {
  img {
    margin-top: 10px;
    height: 60px;
  }
  h2 {
    font-size: 14px;
    font-weight: 400;
  }
  ::v-deep .van-grid-item__content {
    padding: 0 8px;
  }
}
.content {
  .group {
    height: 188px;
    width: 355px;
    padding: 0 10px;
    background-color: #f6f5f6;
    display: flex;
    flex-flow: row wrap;
    align-content: flex-end;
    .am-flexbox-item {
      display: flex;
      width: 172px;
      height: 60px;
      background-color: #fff;
      margin-left: 5px;
      border-radius: 5px;
      margin-bottom: 10px;
      img {
        width: 50px;
        height: 50px;
      }
      .cont {
        margin-left: 15px;
        margin-top: 10px;
        font-size: 14px;
      }
    }
  }
}

.titleandmore {
  position: relative;
  top: -185px;
  display: flex;
  justify-content: space-between;
  padding: 13px;
  .left {
    font-size: 15px;
    font-weight: 700;
    color: #333;
    margin-left: 5px;
  }
  .right {
    font-size: 14px;
    color: #787d82;
  }
}
</style>
